<?php
/**
 * 首页
 * 
 * @version $Id$
 */

class Module_profile
{
	/**
	 * 构造函数
	 */
	function __construct() {
		
	}

	/**
	 * 默认 action
	 */
	function index() {
		$uin = isset($_GET['uin']) ? intval($_GET['uin']) : null;
		
		// 如果没有uin参数，则显示自己的个人主页
		if(empty($uin)) {
			$uin = SessionInfo('uin');
		}
		
		$smarty = loadSmarty();
		
		$is_own = $uin == SessionInfo('uin');
		$smarty->assign('is_own' , $is_own);
		
		
		// 获取用户数据
		loadLib('User');
		$userinfo = USER::getFullInfo($uin);
		if(empty($userinfo)){
			return View::error('该用户信息不存在' );
		}
		$user_logo = User::getLogo($userinfo , 60);
		
		$smarty->assign('user_logo' , $user_logo);
		$smarty->assign('userinfo' , $userinfo);
		//print_r($userinfo);
		
		loadLib('Friend');
		// 判断两人是否是好友
		if(!$is_own) {
			$is_friend = Friend::isFriend($uin , $GLOBALS['CORE']['class']['Session']->getUin());
			$smarty->assign('is_friend' , $is_friend);
		}
		
		// 获取最近一条状态（心情）
		loadLib('Status');
		$status = Status::getLastOne($uin);
		
		$smarty->assign('status' , $status);
		
		// 获取金库
		loadLib('Money');
		$money = Money::get( $uin );
		$money_str = Money::toString($money);
		$smarty->assign('money' , $money);
		$smarty->assign('money_str' , $money_str);
		
		// 获取feed ，获取自己+好友的feed
		loadLib('Feed');
		$get_feeds_uins[] = $uin;
		$feeds = Feed::getList( array($uin) , 0 , 11 );		// 多取一条，为了判断是否有更多feed
		foreach($feeds as $k => $feed) {
			$feeds[$k]['data'] = unserialize($feed['data']);
		}
		
		$smarty->assign('feeds' , $feeds);
		
		$smarty->assign('nav_cur_tab' , $is_own ? 'profile' : '');

		return $smarty->fetch('profile/index.tpl.php');
	}
}

# end of script
